const fs = require('fs')
const { Transform } = require('stream')
const { callback } = require('../gulp-async-task/gulpfile')

exports.default = () => {
    //文件读取流
    const read = fs.createReadStream('normaize.css')
    //文件写入流
    const write = fs.createWriteStream('normaize.min.css')
    //文件转换流
    const transform = new Transform({
        transform: (chunk, encoding, callback) => {
            //核心转换过程实现
            //chunk => 读取流中读取到的内容 (Buffer)
            const input = chunk.toString()
            const output = input.replace(/\s+/g, '').replace(/\/\*.+?\*\//g, '')
            callback(null, output)
        }
    })
    //把读取的文件流导入到文件流中
    read
    .pipe(transform) //转换
    .pipe(write) //写入

    return read
}